package com.lagou.edu.service.impl;

import com.lagou.edu.annotation.CustomAutowired;
import com.lagou.edu.annotation.CustomService;
import com.lagou.edu.annotation.CustomTransactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.factory.BeanFactory;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;
import com.lagou.edu.utils.ConnectionUtils;
import com.lagou.edu.utils.TransactionManager;

/**
 * @author 应癫
 */
@CustomService("transferService")
@CustomTransactional
public class TransferServiceImpl implements TransferService {

    @CustomAutowired
    private AccountDao accountDao = (AccountDao) BeanFactory.getBean("accountDao");

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);
        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);
        accountDao.updateAccountByCardNo(to);
        //测试事务回滚
        int value = 1/0;
        accountDao.updateAccountByCardNo(from);
    }
}
